#define  _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void itob(int n, char s[], int b);
void reverse(char s[]);
int main()
{
	int num;
	char str[100];
	printf("Please enter number: ");
	scanf("%d", &num);
	itob(num, str, 16);
	printf("Result=");
	puts(str);
	system("pause");
	return 0;
}
void itob(int n, char s[], int b)
{
	int i, sign;
	if ((sign = n) < 0)
		n = -n;
	i = 0;
	do {
		if ((n % 16) > 9 && (n % 16) < 16) {
			switch (n % 16) {
			case 10: s[i++] = 'A'; break;
			case 11: s[i++] = 'B'; break;
			case 12: s[i++] = 'C'; break;
			case 13: s[i++] = 'D'; break;
			case 14: s[i++] = 'E'; break;
			case 15: s[i++] = 'F'; break;
			default: break;
			}
		}
		else
			s[i++] = n % 16 + '0';
	} while ((n /= 16) > 0);
	if (sign < 0)
		s[i++] = '-';
	s[i] = '\0';
	reverse(s);
}
void reverse(char s[])
{
	int c, i, j;
	for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
		c = s[i], s[i] = s[j], s[j] = c;
	}
}
